﻿@inherits AntDesignTestBase
@code {
    [Fact]
    public void Renders_a_color_button()
    {
        var cut = Render<Button>(@<Button Color="Color.Red3"></Button> );
        cut.MarkupMatches(@<button class="ant-btn ant-btn-default" style="background-color: #ffa39e; border-color: #ffa39e; color: rgba(0,0,0,0.85);" id:ignore type="button" ant-click-animating-without-extra-node="false" ></button>);
    }

    [Fact]
    public void Ignore_link_animation_when_cliked_using_nonprimary_mouse_button()
    {
        var cut = Render<Button>(@<Button Type="@ButtonType.Default"/>);
        cut.Find("button").MouseUp(new MouseEventArgs 
        {
            Button = 2
        });
        cut.MarkupMatches(@<button class="ant-btn ant-btn-default" id:ignore type="button" ant-click-animating-without-extra-node="false"></button>);
    }

    [Fact]
    public void Link_animation_when_cliked_using_primary_mouse_button()
    {
        var cut = Render<Button>(@<Button Type="@ButtonType.Default"/>
    );
        cut.Find("button").MouseUp(new MouseEventArgs 
        {
            Button = 0
        });
        cut.MarkupMatches(@<button class="ant-btn ant-btn-default" id:ignore type="button" ant-click-animating-without-extra-node="true"></button>);
    }

    [Fact]
    public async Task Button_animation_when_cliked_end_after_some_time()
    {
        var cut = Render<Button>(@<Button Type="@ButtonType.Default"/>);
        cut.Find("button").MouseUp(new MouseEventArgs 
        {
            Button = 0
        });
        cut.MarkupMatches(@<button class="ant-btn ant-btn-default" id:ignore type="button" ant-click-animating-without-extra-node="true"></button>);
        await Task.Delay(550);
        cut.MarkupMatches(@<button class="ant-btn ant-btn-default" id:ignore type="button" ant-click-animating-without-extra-node="false"></button>); 
    }

    class Model
    {        		
        public string? Name { get; set; }
    }       

    [Fact]
    public void Receives_size_from_Form()
    {
        JSInterop.Setup<Window>(JSInteropConstants.DomInfoHelper.GetWindow, _ => true).SetResult(new Window());

        Model _model = new() { Name = "modelValue" };
		var cut = Render<AntDesign.Form<Model>>(
			@<AntDesign.Form Model="@_model" Size="FormSize.Small">       
				<AntDesign.FormItem Label="Test">
						<AntDesign.Button>Test</AntDesign.Button>
				</AntDesign.FormItem>
			</AntDesign.Form>
        );

        var button = cut.FindComponent<AntDesign.Button>();
        cut.Instance.Size.Should().Be(FormSize.Small);
        cut.Instance.Size.Should().Be(cut.Instance.Size);
        button.Instance.FormSize.Should().Be(FormSize.Small);
    }

    [Fact]
    public void Loading_is_rendering()
    {
        var cut = Render<AntDesign.Button>(@<Button Loading>Test</Button>);
        cut.MarkupMatches(@<button class="ant-btn ant-btn-default ant-btn-loading" id:ignore type="button" ant-click-animating-without-extra-node="false">
            <span class="ant-btn-loading-icon">
               <span role="img" class=" anticon anticon-loading" id:ignore>
                  <svg focusable="false" width="1em" height="1em" fill="currentColor" style="pointer-events: none;" class="anticon-spin" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
                    <path d="M988 548c-19.9 0-36-16.1-36-36 0-59.4-11.6-117-34.6-171.3a440.45 440.45 0 0 0-94.3-139.9 437.71 437.71 0 0 0-139.9-94.3C629 83.6 571.4 72 512 72c-19.9 0-36-16.1-36-36s16.1-36 36-36c69.1 0 136.2 13.5 199.3 40.3C772.3 66 827 103 874 150c47 47 83.9 101.8 109.7 162.7 26.7 63.1 40.2 130.2 40.2 199.3.1 19.9-16 36-35.9 36z"></path>
                  </svg>
                </span>
           </span>
            <span>Test</span>
        </button>);
    }

    [Fact]
    public void Should_wrap_in_span_when_NoSpanWrap_set_to_true()
    {
        var cut = Render<AntDesign.Button>(@<AntDesign.Button NoSpanWrap="false">Test</AntDesign.Button>);
        cut.MarkupMatches(@<button class="ant-btn ant-btn-default" id:ignore type="button" ant-click-animating-without-extra-node="false">
            <span>Test</span>
        </button>);
    }

}
